define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'daily/dailys/index' + location.search,
                    add_url: 'daily/dailys/add',
                    edit_url: 'daily/dailys/edit',
                    del_url: 'daily/dailys/del',
                    multi_url: 'daily/dailys/multi',
                    import_url: 'daily/dailys/import',
                    table: 'daily_dailys',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'user_ids', title: __('User_ids'), operate: 'LIKE'},
                        {field: 'date', title: __('Date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'goout_type_name', title: __('Goout_type_name'), searchList: {"未出差":__('未出差'),"开始出差":__('开始出差'),"出差中":__('出差中'),"出差结束":__('出差结束')}, formatter: Table.api.formatter.normal},
                        {field: 'stay_type_name', title: __('Stay_type_name'), searchList: {"未住宿":__('未住宿'),"开始住宿":__('开始住宿'),"住宿中":__('住宿中'),"结束住宿":__('结束住宿')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'continuousnum', title: __('Continuousnum')},
                        {field: 'goOutAccumulatenum', title: __('Gooutaccumulatenum')},
                        {field: 'visitnum', title: __('Visitnum')},
                        {field: 'kaoqinnum', title: __('Kaoqinnum')},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
